package cn.kpi.service.attendance.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import cn.kpi.dao.attendance.AttFjGdDao;
import cn.kpi.service.attendance.IAttFjGdService;

@Service
public class AttFjGdServiceImpl implements IAttFjGdService {
	
	@Autowired
	private AttFjGdDao attFjGdDao;
	
	@Transactional
	public int UpdateAttFjGd(String where,String wheredetail,Long gdbyuserid)throws Exception{
		try{
			int result=0;
			result+=attFjGdDao.UpdateAttDetailByOrgId(wheredetail);
			int temp=result;
			result+=attFjGdDao.UpdateAttSummaryByOrgId(where,gdbyuserid);
			if(result<=temp){
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				return -1;
			}
			
			return result;
		}
		catch(Exception ex){
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}
	
	@Transactional
	public int UpdateAttStatusByBm(String orgsummaryids,int status)throws Exception{
		try{
			int result=0;
			result+=attFjGdDao.UpdateAttOrgSummaryStatusBm(orgsummaryids, status);
			result+=attFjGdDao.UpdateAttSummaryStatusBm(orgsummaryids, status);
			result+=attFjGdDao.UpdateAttDetailStatusBm(orgsummaryids, status);
			return result;
		}
		catch(Exception ex){
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}
	@Transactional
	public int UpdateAttStatus(Long orgsummaryid,int status)throws Exception{
		try{
			int result=0;
			result+=attFjGdDao.UpdateAttOrgSummaryStatus(orgsummaryid, status);
			result+=attFjGdDao.UpdateAttSummaryStatus(orgsummaryid, status);
			result+=attFjGdDao.UpdateAttDetailStatus(orgsummaryid, status);
			return result;
		}
		catch(Exception ex){
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}
}
